home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD ROM Paradise Collection 4
/
CD ROM Paradise Collection 4 1995 Nov.iso
/
win
/
vbsmpls.zip
/
SAMPLES
/
OLEDB
/
OLEDB.BAS
< prev
next >
Wrap
BASIC Source File
|
1994-03-24
|
5KB
|
120 lines
'*******************************************************************'
'* *'
'* OLEDB.BAS - Routines that store and retrieve OLE objects *'
'* and files in a database field. *'
'* *'
'* NOTE: No error trapping has been implemented in this module. *'
'* *'
'*******************************************************************'
Option Explicit
Const OLE_SAVE_TO_FILE = 11 'OLE Action constant
Const OLE_LOAD_FROM_FILE = 12 'OLE Action constant
Const CHUNK_SIZE = 32000 'Size of file transfer pieces
'Extracts an Access 1.x OLE field and inserts the object in the
'OLE2 control
'
'NOTE: No error trapping or checking implemented
'
Function AccessFieldToOLE (oleObject As Control, fdObject As Field)
Dim eError As Integer
Dim iFileNumber As Integer
Dim wOffsetToObject As Integer
iFileNumber = FreeFile 'Get a free file number
Open App.Path & "\OLE.TMP" For Binary As iFileNumber 'Create temp
eError = FieldToFileStream(iFileNumber, fdObject) 'Get data
Get iFileNumber, 3, wOffsetToObject 'Get offset to object
Seek iFileNumber, wOffsetToObject + 1 'Move to start of object
oleObject.FileNumber = iFileNumber 'Point OLE control to file
oleObject.Action = OLE_LOAD_FROM_FILE 'Load OLE object from file
Close iFileNumber 'Close temp file
Kill App.Path & "\OLE.TMP" 'Delete temp file
AccessFieldToOLE = 0 'Can be modified to return errors
End Function
'Extracts data from field and places it into a file stream
'
Function FieldToFileStream (iFileNumber As Integer, fdObject As Field) As Integer
Dim sChunkHolder As String
Dim lChunkCount As Long
Dim lChunkRemainder As Long
Dim i As Long
lChunkCount = fdObject.FieldSize() \ CHUNK_SIZE
lChunkRemainder = fdObject.FieldSize() Mod CHUNK_SIZE
For i = 0 To lChunkCount - 1
sChunkHolder = fdObject.GetChunk(i * CHUNK_SIZE, CHUNK_SIZE)
Put iFileNumber, , sChunkHolder
Next
If lChunkRemainder > 0 Then
sChunkHolder = fdObject.GetChunk(lChunkCount * CHUNK_SIZE, lChunkRemainder) 'Get remaining data
Put iFileNumber, , sChunkHolder
End If
FieldToFileStream = 0 'Can be modified to return errors
End Function
'Extracts OLE2 object from database and inserts it into the
'OLE2 control
'
'NOTE: No error trapping or checking implemented
'
Function FieldToOLE (oleObject As Control, fdObject As Field)
Dim eError As Integer
Dim iFileNumber As Integer
iFileNumber = FreeFile
Open App.Path & "\OLE.TMP" For Binary As iFileNumber 'Create temp
eError = FieldToFileStream(iFileNumber, fdObject) 'Get data
Seek iFileNumber, 1 'Move to start of file
oleObject.FileNumber = iFileNumber 'Point OLE control to file
oleObject.Action = OLE_LOAD_FROM_FILE 'Load OLE object from file
Close iFileNumber 'Close temp file
Kill App.Path & "\OLE.TMP" 'Delete temp file
FieldToOLE = 0 'Can be modified to return errors
End Function
'Copies the remaining portion of an open file stream to a
'database field
'
Function FileStreamToField (iFileNumber As Integer, fdObject As Field) As Integer
Dim sChunkHolder As String
Dim lChunkCount As Long
Dim lChunkRemainder As Long
Dim i As Long
sChunkHolder = Space$(CHUNK_SIZE)
lChunkCount = (LOF(iFileNumber) - Seek(iFileNumber) + 1) \ CHUNK_SIZE
lChunkRemainder = (LOF(iFileNumber) - Seek(iFileNumber) + 1) Mod CHUNK_SIZE
For i = 1 To lChunkCount
Get iFileNumber, , sChunkHolder
fdObject.AppendChunk (sChunkHolder)
Next
If lChunkRemainder > 0 Then
sChunkHolder = Space$(lChunkRemainder)
Get iFileNumber, , sChunkHolder
fdObject.AppendChunk (sChunkHolder)
End If
FileStreamToField = 0 'Can be modified to return errors
End Function
'Extracts the OLE2 object from the OLE2 control and places it into
'the database field
'
'NOTE: No error trapping or checking implemented
'
Function OLEToField (oleObject As Control, fdObject As Field) As Integer
Dim eError As Integer
Dim iFileNumber As Integer
iFileNumber = FreeFile
Open App.Path & "\OLE.TMP" For Binary As iFileNumber 'Create temp
oleObject.FileNumber = iFileNumber 'Point OLE control to file
oleObject.Action = OLE_SAVE_TO_FILE 'Store OLE object in temp file
Seek iFileNumber, 1 'Move to stream start
fdObject = "" 'Clear field
eError = FileStreamToField(iFileNumber, fdObject) 'Put data
Close iFileNumber 'Close temp file
Kill App.Path & "\OLE.TMP" 'Delete temp file
OLEToField = 0 'Can be modified to return errors
End Function